import time

from DrissionPage import Chromium

from chaojiying import PostPic

tab = Chromium().latest_tab

tab.get("https://www.bilibili.com/")

login_entry = tab.ele('x=//div[@class="header-login-entry"]')

login_entry.click()

username_input = tab.ele('x=//input[@placeholder="请输入账号"]')

username_input.input("admin")


password_input = tab.ele('x=//input[@placeholder="请输入密码"]')

password_input.input("123456")

submit_btn = tab.ele('x=//div[@class="btn_primary "]')

submit_btn.click()


time.sleep(3)

geetest_widget = tab.ele('x=//div[@class="geetest_widget"]')

geetest_widget.get_screenshot("./codes/rect.png")

geetest_widget_bytes = geetest_widget.get_screenshot(as_bytes=True)

ret = PostPic(geetest_widget_bytes, "9004")

points = []
points_strs = ret['pic_str'].split('|')
for points_str in points_strs:
	x, y = points_str.split(',')
	points.append((int(x), int(y)))

print(points)

for x, y in points:
	tab.actions.move_to(geetest_widget, x, y).click()
	time.sleep(1)

geetest_commit_tip = tab.ele('x=//div[@class="geetest_commit_tip"]')
geetest_commit_tip.click()














